package cn.tedu.bootdemo;

import org.junit.jupiter.api.Test;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;

import javax.swing.plaf.PanelUI;

public class testEncode {

    @Test
    public void testEncode(){
        BCryptPasswordEncoder passwordEncoder = new BCryptPasswordEncoder();
        String rawPassword = "1234";
        for (int i = 0; i < 10; i++) {
            String encodePassword = passwordEncoder.encode(rawPassword);
            System.out.println("原密码:"+rawPassword+",密文:"+encodePassword);
        }

        /*原密码:1234,密文:$2a$10$W2xqKqDaeJwWma8NQ6dl0eE/6pJtoU649tGyLChAd6xDKvfG.ypuu
            原密码:1234,密文:$2a$10$PCI5ml2s85393.Qoxshvwu/j2UEy7MONF5oo.1vu7TPrfWYaCJj8O
            原密码:1234,密文:$2a$10$LjDKcVYUdtJvLQue2weNz.19R4DfJryzoSDEBRxrVYvRZAwExrY4y
            原密码:1234,密文:$2a$10$9nKMUGZ0AQ9XJmS8oElgR.ZPVfPJGxxbmROW728lBcBRFwnEsEXjO
            原密码:1234,密文:$2a$10$2/9WGdsu97YCx8zaRj.WYeqdm1SAb1hkFhb/I2qlx2WOoRa3a/sAK
            原密码:1234,密文:$2a$10$.19gIfb74/A9/FZyE3aADu.fChoU8pb2Qn1Vw7jD5B0gceO5.l5jO
            原密码:1234,密文:$2a$10$R2IHSztD3nlSVRG7GbdvQOSrbmKLDJRzycnyF8ZAWLqbe5cGzus2K
            原密码:1234,密文:$2a$10$1VMkNQ97gEDwpH9vMDSox.zTm.f0r5xXsiw380R1MZu9ghdO9gGB2
            原密码:1234,密文:$2a$10$hy1zzQHurUDdyL.8xlJ/s.mImz1rx4jwlwC1Wdq1B.0eFNG.AoC0y
            原密码:1234,密文:$2a$10$7OvehCm/m4z0vubN9InbfuObon62EN1bROpGO1GMsQOKD6bkHLCqK

            Process finished with exit code 0
                */
    }

    @Test
    public void testMatch(){
        BCryptPasswordEncoder passwordEncoder = new BCryptPasswordEncoder();
        String rawPassword = "1234";
        String[] encodePasswords = {
                "$2a$10$7OvehCm/m4z0vubN9InbfuObon62EN1bROpGO1GMsQOKD6bkHLCqK",
                "$2a$10$R2IHSztD3nlSVRG7GbdvQOSrbmKLDJRzycnyF8ZAWLqbe5cGzus2K",
                "$2a$10$LjDKcVYUdtJvLQue2weNz.19R4DfJryzoSDEBRxrVYvRZAwExrY4y"
        };
        for (int i = 0; i < encodePasswords.length; i++) {
            boolean result = passwordEncoder.matches(rawPassword, encodePasswords[i]);
            System.out.println("原密码:"+rawPassword+",密文:"+encodePasswords[i]+",结果:"+result);
        }
    }
}
